package com.pzhu.user.domain.entity.converter;

import com.pzhu.user.domain.entity.Menu;
import com.pzhu.user.domain.enums.MenuType;
import com.pzhu.user.domain.ro.MenuCreateRO;
import com.pzhu.user.domain.ro.MenuUpdateRO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
import com.pzhu.base.common.utils.json.JSONUtils;

@Mapper(
        componentModel = MappingConstants.ComponentModel.SPRING,
        imports = {MenuType.class, JSONUtils.class})
public interface MenuEntityConverter {

    @Mapping(target = "deletedId", ignore = true)
    @Mapping(target = "updatedAt", ignore = true)
    @Mapping(target = "id", ignore = true)
    @Mapping(target = "createdAt", ignore = true)
    @Mapping(target = "type", expression = "java(MenuType.of(menuCreateRo.getType()))")
    @Mapping(target = "menuTagList", expression = "java(JSONUtils.toJsonString(menuCreateRo.getMenuTagList()))")
    Menu convert(MenuCreateRO menuCreateRo);

    @Mapping(target = "deletedId", ignore = true)
    @Mapping(target = "updatedAt", ignore = true)
    @Mapping(target = "createdAt", ignore = true)
    @Mapping(target = "type", expression = "java(MenuType.of(menuUpdateRo.getType()))")
    @Mapping(target = "menuTagList", expression = "java(JSONUtils.toJsonString(menuUpdateRo.getMenuTagList()))")
    Menu convert(Long id, MenuUpdateRO menuUpdateRo);
}
